package com.example.demo69.controller;

import com.example.demo69.entity.Message;
import com.example.demo69.service.MessageService;
import com.example.demo69.util.Result;
import com.example.demo69.vo.PageInfo;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (Message)表控制层
 *
 * @author david
 * @since 2025-06-17 08:13:42
 */
@RestController
public class MessageController {
    /**
     * 服务对象
     */
    @Resource
    private MessageService messageService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Message selectOne(Integer id) {
        return this.messageService.queryById(id);
    }

    @PostMapping("/msgList")
    public Result queryList(@RequestBody PageInfo pageInfo) {
        PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
        com.github.pagehelper.PageInfo<Message> page = new com.github.pagehelper.PageInfo<>(messageService.queryAll(new Message()));
        return Result.success(page);
    }

    @PostMapping("/msgInsert")
    public Result insert(@RequestBody Message message) {
        messageService.insert(message);
        return Result.success();
    }
}
